home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 1 Issue 2
/
PDCD-1 - Issue 02.iso
/
_utilities
/
utilities
/
003
/
_gs
/
!GS
/
c
/
IINIT
< prev
next >
Wrap
Text File
|
1991-10-26
|
6KB
|
208 lines
/* Copyright (C) 1989, 1990, 1991 Aladdin Enterprises. All rights reserved.
Distributed by Free Software Foundation, Inc.
This file is part of Ghostscript.
Ghostscript is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY. No author or distributor accepts responsibility
to anyone for the consequences of using it or for whether it serves any
particular purpose or works at all, unless he says so in writing. Refer
to the Ghostscript General Public License for full details.
Everyone is granted permission to copy, modify and redistribute
Ghostscript, but only under the conditions described in the Ghostscript
General Public License. A copy of this license is supposed to have been
given to you along with Ghostscript so you can know your rights and
responsibilities. It should be in a file named COPYING. Among other
things, the copyright notice and this notice must be preserved on all
copies. */
/* iinit.c */
/* Initialize internally known objects for Ghostscript interpreter */
#include "ghost.h"
#include "alloc.h"
#include "dict.h"
#define INCLUDE_ERROR_NAMES /* see errors.h */
#include "errors.h"
#include "name.h"
#include "oper.h"
#include "save.h" /* for alloc_refs */
#include "store.h"
/* Implementation parameters */
#define systemdict_size 401 /* a nice prime number */
#define op_array_table_size 100 /* arbitrary */
/* Standard dictionaries */
ref name_errordict;
/* Error names */
ref name_ErrorNames;
/* The operator tables */
op_def_ptr *op_def_table;
uint op_def_count;
ref op_array_table; /* t_array, definitions of `operator' procedures */
ushort *op_array_nx_table; /* name indices for same */
uint op_array_count;
/* Enter a name and value into systemdict */
void
initial_enter_name(char *nstr, ref *pref)
{ ref nref;
name_enter(nstr, &nref);
if ( dict_put(&systemdict, &nref, pref) )
lprintf("dict_put failed!\n"),
gs_exit(1);
}
/* Initialize objects other than operators */
void
obj_init()
{
/* Initialize the standard objects */
ref vmark, vnull;
make_tv(&vmark, t_mark, intval, 0);
make_tv(&vnull, t_null, intval, 0);
/* Create the system dictionary */
dict_create(systemdict_size, &systemdict);
dstack[1] = dstack[0]; /* just during initialization */
/* Initialize the predefined names other than operators */
initial_enter_name("mark", &vmark);
initial_enter_name("null", &vnull);
/* Create other system-known names */
name_enter("errordict", &name_errordict);
name_enter("ErrorNames", &name_ErrorNames);
/* Create the error name table */
{ int n = sizeof(gs_error_names) / sizeof(char _ds *) - 1;
int i;
ref era;
make_tasv(&era, t_array, a_read + a_execute, n, refs,
alloc_refs(n, "obj_init(ErrorNames)"));
for ( i = 0; i < n; i++ )
name_enter((char *)gs_error_names[i], era.value.refs + i);
dict_put(&systemdict, &name_ErrorNames, &era);
}
}
/* Initialize the operators */
/* Non-graphics operators */
extern op_def
zarith_op_defs[], zarray_op_defs[], zcontrol_op_defs[],
zdict_op_defs[], zfile_op_defs[], zfileio_op_defs[], zgeneric_op_defs[],
zmath_op_defs[], zmisc_op_defs[], zpacked_op_defs[],
zrelbit_op_defs[], zstack_op_defs[], zstring_op_defs[],
ztype_op_defs[], zvmem_op_defs[]
#ifdef LEVEL2
,
/* Level 2 */
z2filter_op_defs[]
#endif
;
/* Graphics operators */
extern op_def
zchar_op_defs[], zcolor_op_defs[], zdevice_op_defs[],
zfont_op_defs[], zfont0_op_defs[], zfont2_op_defs[],
zgstate_op_defs[], zht_op_defs[],
zmatrix_op_defs[], zpaint_op_defs[], zpath_op_defs[],
zpath2_op_defs[]
#ifdef LEVEL2
,
/* Level 2 */
z2path_op_defs[]
#endif
;
private op_def_ptr op_defs_all[] = {
/* Non-graphics operators */
zarith_op_defs, zarray_op_defs, zcontrol_op_defs,
zdict_op_defs, zfile_op_defs, zfileio_op_defs, zgeneric_op_defs,
zmath_op_defs, zmisc_op_defs, zpacked_op_defs,
zrelbit_op_defs, zstack_op_defs, zstring_op_defs,
ztype_op_defs, zvmem_op_defs,
#ifdef LEVEL2
/* Level 2 */
z2filter_op_defs,
#endif
/* Graphics operators */
zchar_op_defs, zcolor_op_defs, zdevice_op_defs,
zfont_op_defs, zfont0_op_defs, zfont2_op_defs,
zgstate_op_defs, zht_op_defs,
zmatrix_op_defs, zpaint_op_defs, zpath_op_defs,
zpath2_op_defs,
#ifdef LEVEL2
/* Level 2 */
z2path_op_defs,
#endif
/* end marker */
(op_def_ptr)0
};
/* Run the initialization procedures of the individual operator files. */
void
zop_init()
{ op_def_ptr _ds *tptr;
op_def_ptr def;
for ( tptr = op_defs_all; *tptr != 0; tptr++ )
{ for ( def = *tptr; def->oname != 0; def++ ) ;
if ( def->proc != 0 )
((void (*)(P0()))(def->proc))();
}
}
/* Initialize the operator table. */
void
op_init()
{ int count = 1;
op_def_ptr _ds *tptr;
op_def_ptr def;
char _ds *nstr;
/* Do a first pass just to count the operators. */
for ( tptr = op_defs_all; *tptr != 0; tptr ++ )
for ( def = *tptr; def->oname != 0; count++, def++ )
;
/* Do a second pass to construct the operator table, */
/* and enter the operators in systemdict. */
op_def_table = (op_def_ptr *)alloc(count, sizeof(op_def_ptr),
"op_init(op_def_table)");
op_def_count = count;
count = 1;
for ( tptr = op_defs_all; *tptr != 0; tptr ++ )
for ( def = *tptr; (nstr = def->oname) != 0; count++, def++ )
{ /* Enter an operator into systemdict. */
/* The first character of the name is a digit */
/* giving the minimum acceptable number of operands. */
/* For now, we just skip over it. */
ref oper;
make_oper(&oper, count, (dummy_op_proc_p)(def->proc));
interp_fix_op(&oper); /* optimize if possible */
initial_enter_name(nstr + 1, &oper);
op_def_table[count] = def;
}
/* Allocate the table for `operator' procedures. */
{ ref *tbody =
alloc_refs(op_array_table_size, "op_array table");
make_tasv(&op_array_table, t_array, a_read+a_execute,
op_array_table_size, refs, tbody);
refset_null(tbody, op_array_table_size);
op_array_nx_table =
(ushort *)alloc(op_array_table_size, sizeof(ushort),
"op_array nx table");
op_array_count = 0;
}
}
/* Initialize variables that hold name constants. */
void
init_names(register names_def _ds *pnd)
{ for ( ; pnd->vname != 0; pnd++ )
name_enter(pnd->vname, pnd->pvref);
}